package com.yy.controller.front;

import com.yy.entity.front.ShoppingCart;
import com.yy.service.front.ShoppingCartService;
import com.yy.service.front.UserService;
import com.yy.utils.R;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * create by KongFuning on 2022/8/4
 */
@RestController
@RequestMapping("/shoppingCart")
@Slf4j
public class ShoppingCartController {

    @Autowired
    private ShoppingCartService shoppingCartService;

    /*
    * 获取当前用户的购物车列表
    * */
    @GetMapping("/list")
    public R cartList(){
        return shoppingCartService.cartList();
    }

    /*
    * 添加到购物车
    * */
    @PostMapping("/add")
    public R addToCart(@RequestBody ShoppingCart shoppingCart){
        return shoppingCartService.addToCart(shoppingCart);
    }

    /*
    * 清空购物车
    * */
    @DeleteMapping("/clean")
    public R deleteCart(){
        return shoppingCartService.deleteCart();
    }

    /*
    * 减少购物车菜品
    * */
    @PostMapping("/sub")
    public R subCart(@RequestBody ShoppingCart shoppingCart){
        return shoppingCartService.subCart(shoppingCart);
    }
}
